package cn.com.zhbs.common.ucpaas;


import cn.com.zhbs.common.ucpaas.restDemo.client.AbsRestClient;
import cn.com.zhbs.common.ucpaas.restDemo.client.JsonReqClient;
import cn.com.zhbs.common.ucpaas.restDemo.client.XmlReqClient;
import com.google.gson.Gson;

import java.io.IOException;
import java.util.Map;

public class Testmsm {

	static AbsRestClient InstantiationRestAPI(boolean enable) {
		if(enable) {
			return new JsonReqClient();
		} else {
			return new XmlReqClient();
		}
	}

	public static Boolean testTemplateSMS(boolean json,String accountSid,String authToken,String appId,String templateId,String to,String param){
		try {
			String result=InstantiationRestAPI(json).templateSMS(accountSid, authToken, appId, templateId, to, param);
			System.out.println("Response content is: " + result);
			Gson gson = new Gson();
			Map<String,Object> resultMap = gson.fromJson(result, Map.class);
			Map<String,Object> resp=(Map)resultMap.get("resp");
			if(resp.get("respCode").equals("000000"))
			{
				return true;
			}
			else
			{
				return false;
			}

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}
	}

	/**
	 * 测试说明 参数顺序，请参照各具体方法参数名称
	 * 参数名称含义，请参考rest api 文档
	 * @author Glan.duanyj
	 * @date 2014-06-30
	 * @param params[]
	 * @return void
	 * @throws IOException 
	 * @method main
	 */


	public static void main(String[] args) throws IOException {

		boolean json=true;
		int code=(int) (Math.random()*9000+1000);
		System.out.println(code);
			String accountSid="123";
			String token="123";
			String appId="123";
			String templateId="123";
			String to="11111111111";
			String para=code+",3";
		System.out.println(testTemplateSMS(json, accountSid,token,appId, templateId,to,para));
	}
}
